﻿using System.Collections.Generic;

namespace Genesis.Domain
{

    using Genesis.Infrastructure;
    using Genesis.Infrastructure.Domain;

    public class Forum : Entity
    {

        private IList<Forum> forums = new List<Forum>();

        private IList<Moderator> moderators = new List<Moderator>();

        private IList<Thread> threads = new List<Thread>();

        public virtual int Sequence { get; set; }

        [Signature]
        public virtual string Title { get; protected set; }

        public virtual string Description { get; set; }

        public virtual bool IsModerated { get; set; }

        public virtual bool IsEnabled { get; set; }

        public virtual bool IsVisible { get; set; }

        public virtual IEnumerable<Forum> Forums { get { return forums; } }

        public virtual IEnumerable<Moderator> Moderators { get { return moderators; } }

        public virtual IEnumerable<Thread> Threads { get { return threads; } }

        public virtual void AddForum(Forum forum)
        {
            
            Logic.Check(forum != null, "Forum can not be null!");
            Logic.Check(forum != this, "Forum can not be self!");
            
            if (!forums.Contains(forum))
                forums.Add(forum);
        
        }

        public virtual void RemoveForum(Forum forum)
        {
        
            Logic.Check(forum != null, "Forum can not be null!");
            Logic.Check(forum != this, "Forum can not be self!");
            
            if (forums.Contains(forum))
                forums.Remove(forum);
        
        }

        public virtual void AddModerator(Moderator moderator)
        {
        
            Logic.Check(moderator != null, "Moderator can not be null!");
            
            if (!moderators.Contains(moderator))
                moderators.Add(moderator);
        
        }

        public virtual void RemoveModerator(Moderator moderator)
        {
        
            Logic.Check(moderator != null, "Moderator can not be null!");
            
            if (moderators.Contains(moderator))
                moderators.Remove(moderator);
        
        }

        public virtual void AddThread(Thread thread)
        {
        
            Logic.Check(thread != null, "Thread can not be null!");
            
            if (!threads.Contains(thread))
                threads.Add(thread);
        
        }

        public virtual void RemoveThread(Thread thread)
        {
        
            Logic.Check(thread != null, "Thread can not be null!");
            
            if (threads.Contains(thread))
                threads.Remove(thread);
        
        }

        public virtual void SetTitle(string title)
        {
        
            Logic.Check(!string.IsNullOrEmpty(title) && !string.IsNullOrWhiteSpace(title), "Title can not be null, empty or whitespace!");
            
            Title = title.Trim();
        
        }

        public Forum(string title)
        {
        
            SetTitle(title);
        
        }

        protected Forum() { }

    }

}